﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QAAdmin.BusinessObject;

namespace QAAdmin.UI
{
    public partial class frmPetugas : BaseForm
    {        
        private TipeSPT tipe;
        private IList<Petugas> lstPetugasOffline;    

        private List<string> namapetugas = new List<string>();
        public List<string> NamaPetugas
        {
            get { return namapetugas; }
            set { namapetugas = value; }
        }

        public frmPetugas()
        {
            InitializeComponent();
            this.tipe = QAController.TipeSPT; 
        }

        private void frmPetugas_Load(object sender, EventArgs e)
        {
             try
            {
                if (tipe == TipeSPT.Balance)
                    lstPetugasOffline = QAController.GetOfflinePetugasBalance();
                else
                    lstPetugasOffline = QAController.GetOfflinePetugasUnBalance();

                lstPetugas.Items.Clear();
                foreach (Petugas p in lstPetugasOffline)
                    lstPetugas.Items.Add(p);

                if (lstPetugas.Items.Count > 0)
                    lstPetugas.SelectedIndex = 0;                  
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }               

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (lstPetugas.SelectedIndices.Count == 0)
            {
                MessageBox.Show("Tidak ada petugas yang dipilih", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }            
            foreach (Petugas p in lstPetugas.SelectedItems)
            {
                namapetugas.Add(p.Username);
            }
            this.DialogResult = DialogResult.OK;
        }      
    }
}
